﻿@model IEnumerable<ServiceLayer.PostServices.SimplePostDto>

@{
    ViewBag.Title = "Posts";
}

<h2>Posts</h2>

@if (TempData["message"] != null)
{
    <div class="text-success">@TempData["message"]</div><br />
}
@if (TempData["errorMessage"] != null)
{
    <div class="text-danger"><strong>@TempData["errorMessage"]</strong></div>
}

<p>
    This is a demonstration of <a href="https://github.com/JonPSmith/GenericServices" target="_blank">GenericServices'</a>
    database CRUD (Create, Read, Update/Edit and Delete) services done synchronously, i.e no wait states to improve web site capacity.
    (See @Html.ActionLink("Posts Async", "Index", "PostsAsync") for async versions of the same commands).
</p>
<p>
    Below you will see a table of posts which can be manipulated. We have chosen a POST as an example as it has the following attributes: 
</p>
<ul>
    <li>When we list them we want 'shape' what the user sees, i.e. we leave out the post content but include the blogger Name and Tags.</li>
    <li>The create and edit commands are non-trivial because Posts links to other tables, like author and the tags.</li>
</ul> 
<hr/>

<div>
    <span>@Html.ActionLink("Create New Post", "Create") | @Html.ActionLink("Tags Page", "Index", "Tags") | @Html.ActionLink("Blogs Page", "Index", "Blogs") | @Html.ActionLink("Reset Blogs data", "Reset")</span>
    <span class="pull-right"><strong>@Html.ActionLink("Explanation of the code", "CodeView")</strong></span>
</div>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.BloggerName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Title)
        </th>
        <th>
            Last updated
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TagNames)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.BloggerName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Title)
            </td>
            <td>
                @item.LastUpdatedUtc.ToShortDateString()
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.TagNames)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.PostId }) |
                @Html.ActionLink("Details", "Details", new { id=item.PostId }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.PostId })
            </td>
        </tr>
    }

</table>

<span>
    @Html.ActionLink("Delay for 500ms (Sync)", "Delay")
     Useful for checking capacity of web server
</span>